package com.msb.gateway.config;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/****************************************************
 * 基于Java 类的方式配置gateway路由
 *
 * @author lbf
 * @date 2025/7/7 15:39
 ****************************************************/
//@Configuration
public class GateWayConfig {

    //@Bean
    public RouteLocator customRouteLocator(RouteLocatorBuilder routeLocatorBuilder){
        /**
         * 构建 routes
         *
         * todo 注意：
         *     若要配置多个路由规则，则需要构建多个 RouteLocatorBuilder（即注入多个RouteLocator）
         */
        RouteLocatorBuilder.Builder routes = routeLocatorBuilder.routes();
        /**
         * 配置路由规则
         */
        routes.route("path_msb",
                r -> r.path("/msb/**") //断言
                .uri("http://localhost:9001") //提供服务的uri  http://localhost:9001/nacos-provider
        );

        return routes.build();
    }
}


